<template>
  <div class="send-list">
    <div class="flex flex-align-items-center flex-justify-content-between">
      <!--      <div class="tabpanel-title">-->
      <!--        {{ $t('component.sendList.1') }}-->
      <!--        <span class="color-primary ml5">3</span>-->
      <!--        / 10 {{ $t('component.sendList.2') }}-->
      <!--      </div>-->
      <div class="tabpanel-btn">
        <button @click="handleAdd">{{ $t('component.sendList.3') }}</button>
      </div>
    </div>
    <!-- <el-row class="mt20">
      <el-col :span="6">
        <el-cascader :value="selectType" :options="typeList" :props="{ value: 'id', label: 'showName', children: 'categoryList' }" :placeholder="$t('component.sendList.4')" @change="handleMultiTypeChange" style="width: 100%"></el-cascader>
      </el-col>
      <el-col :span="8" :offset="10">
        <el-input :placeholder="$t('component.sendList.5')" v-model="params.name" style="width: 100%">
          <i slot="suffix" class="el-input__icon el-icon-search"></i>
        </el-input>
      </el-col>
    </el-row> -->
    <div class="goods-list mt20">
      <div class="godds-item flex" v-for="item in list" :key="item.id">
        <div class="flex-none">
          <img class="goods-img" :src="item.showImg" alt="" />
        </div>
        <div class="flex-auto width0">
          <div class="goods-info flex flex-column flex-justify-content-between">
            <el-row>
              <el-col :span="20">
                <div class="goods-name">{{ item.name }}</div>
              </el-col>
              <el-col :span="4" class="text-right">
                <div class="goods-price">{{ item.price | num2Money }} KZ</div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="20">
                <div class="goods-desc">{{ item.des }}</div>
              </el-col>
              <el-col :span="4"> </el-col>
            </el-row>
            <el-row>
              <el-col :span="20">
                <div class="goods-desc">{{ $t('component.sendList.9') }}：{{ item.views }}</div>
              </el-col>
              <el-col :span="4"> </el-col>
            </el-row>
            <el-row type="flex" align="middle">
              <el-col :span="12">
                <el-link class="mr20" @click="handleDetail(item)">{{ $t('component.sendList.10') }}</el-link>
                <el-link class="mr20" @click.stop="handleEdit(item)">{{ $t('component.sendList.8') }}</el-link>
              </el-col>
              <el-col class="text-right" :span="12">
                <el-button type="primary" @click.stop="handleMeal(item)">{{ $t('component.sendList.7') }}</el-button>
              </el-col>
            </el-row>
          </div>
        </div>
      </div>
    </div>
    <div class="text-center">
      <el-pagination :page-size="params.pageSize" :pager-count="11" layout="prev, pager, next" :total="total" @current-change="handleCurrent" @pre-click="handlePre" @next-click="handleNext"> </el-pagination>
    </div>
    <!-- <div class="recommend-content mt20">
      <div class="flex flex-wrap">
        <div class="recommend-col" v-for="item in list" :key="item.id">
          <div class="recommend-item" @click="handleDetail(item)">
            <div class="recommend-item-info">
              <img class="recommend-item-img" :src="item.showImg" alt="" />
              <div class="recommend-item-title mv10">
                <span class="recommend-tag" v-if="item.tag === '1' || item.tag === '3' ">{{ $t('component.sendList.6') }}</span>
                {{ item.name }}
              </div>
              <div class="flex flex-justify-content-between flex-align-items-center">
                <span class="recommend-item-price">{{ item.price | num2Money }} KZ</span>
              </div>
            </div>
            <div class="recommend-item-btns">
              <div class="recommend-item-btn" @click.stop="handleMeal(item)">{{ $t('component.sendList.7') }}</div>
              <div class="recommend-item-btn" @click.stop="handleEdit(item)">{{ $t('component.sendList.8') }}</div>
            </div>
          </div>
        </div>
      </div>
    </div> -->
    <el-dialog title="Adicionar" :visible.sync="addDialogVisible" width="80%" :close-on-click-modal="false" :close-on-press-escape="false" :destroy-on-close="true">
      <add-goods :goods="editGoods" @success="handleAddSuccess" />
    </el-dialog>
  </div>
</template>
<script>
import Api from '@/api';
import AddGoods from '@/components/add-goods';
import { Domain } from '@/constants';
export default {
  name: 'SendList',
  components: { AddGoods },
  data() {
    return {
      domain: Domain,
      addDialogVisible: false,
      params: {
        pageSize: 20,
        pageNo: 1,
        remark: '',
        sectionId: '',
        categoryId: '',
      },
      total: 0,
      selectType: [],
      list: [],
      typeList: [],
      editGoods: {},
    };
  },
  created() {
    this.loadType();
    this.loadSendList();
  },
  methods: {
    // 已发送列表
    loadSendList() {
      Api.getSendList(this.params).then((res) => {
        const { rows = [], total } = res;
        this.total = total;
        this.list = rows.map((item) => {
          const img = item.imgList ? JSON.parse(item.imgList)[0] : '';
          return Object.assign(item, { showImg: Domain + img });
        });
      });
    },
    handleMultiTypeChange(value) {
      this.selectType = value;
      value[0] ? (this.params.sectionId = value[0]) : '';
      value[1] ? (this.params.categoryId = value[1]) : '';
    },
    loadType() {
      Api.goodsTypeList().then((res) => {
        this.typeList = res;
      });
    },
    handleAdd() {
      this.editGoods = {};
      this.addDialogVisible = true;
    },
    handleAddSuccess() {
      this.addDialogVisible = false;
      this.loadSendList();
    },
    handleDetail(item) {
      this.$router.push({
        path: '/detail',
        query: {
          id: item.id,
        },
      });
    },
    handleMeal(item) {
      this.$router.push({
        path: '/meal',
        query: {
          id: item.id,
        },
      });
    },
    handleEdit(item) {
      this.editGoods = item;
      this.addDialogVisible = true;
    },
    handleCurrent(page) {
      this.params.pageNo = page;
      this.loadSendList();
    },
    handlePre(page) {
      this.params.pageNo = page;
      this.loadSendList();
    },
    handleNext(page) {
      this.params.pageNo = page;
      this.loadSendList();
    },
  },
};
</script>
<style lang="scss" scoped>
.tabpanel-title {
  position: relative;
  font-size: 24px;
  color: #333;
  font-weight: bold;
  .color-primary {
    color: #fb8c24;
  }
}
.tabpanel-btn {
  button {
    width: 141px;
    height: 40px;
    background: #fb7924;
    border-radius: 4px;
    color: #fff;
    line-height: 38px;
    border: none;
    outline: none;
    cursor: pointer;
    &:hover {
      background: #fdaf66;
    }
    &:active {
      background: #e27e20;
    }
  }
}
/* list */
.goods-list {
  overflow: auto;
}
.godds-item {
  background-color: #fff;
  border-radius: 4px;
  padding: 16px 24px;
  margin-bottom: 24px;
}
.goods-img {
  border: 1px solid #707070;
  border-radius: 4px;
  width: 180px;
  height: 180px;
  display: inline-block;
  margin-right: 24px;
}
.goods-info {
  width: 100%;
  height: 180px;
}
.goods-name {
  color: #595959;
  font-size: 20px;
  font-weight: bold;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.goods-price {
  color: #333;
  font-weight: bold;
  font-size: 18px;
}
.goods-desc {
  color: #999999;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.goods-user {
  font-size: 14px;
  color: #999999;
  display: flex;
  align-items: center;
}
.goods-user-head {
  width: 24px;
  height: 24px;
  background: #f2f2f2;
  border-radius: 50%;
  display: inline-block;
}
/* 未使用 */
.recommend-col {
  width: calc((100% - 96px) / 4);
  box-sizing: border-box;
  background-color: #fff;
  border-radius: 4px;
  margin-right: 32px;
  margin-bottom: 32px;
  overflow: hidden;
  &:nth-child(4n) {
    margin-right: 0;
  }
  .recommend-item-info {
    padding: 16px 16px 0;
    .recommend-item-img {
      height: 230px;
      width: 100%;
      display: block;
    }
    .recommend-item-title {
      color: #595959;
      font-size: 20px;
      height: 50px;
      width: 100%;
      text-overflow: ellipsis;
      overflow: hidden;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      .recommend-tag {
        color: #fff;
        font-size: 12px;
        background: linear-gradient(235deg, #ff7144 0%, #f63e2d 100%);
        display: inline-block;
        padding: 5px 10px;
        border-radius: 4px;
      }
    }
    .recommend-item-favorited {
      color: #fb5724;
    }
    .recommend-item-userinfo {
      font-size: 16px;
      color: #999999;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      img {
        width: 24px;
        height: 24px;
        border-radius: 100%;
        display: inline-block;
        background-color: red;
        margin-right: 5px;
      }
    }
    .recommend-item-price {
      font-size: 24px;
      color: #fb8c24;
      font-family: Arial Black;
      margin-bottom: 10px;
    }
  }
  .recommend-item-btns {
    display: flex;
    height: 45px;
    box-sizing: border-box;
    border-top: 1px solid #e8e8e8;
    .recommend-item-btn {
      flex: 1;
      width: 50%;
      box-sizing: border-box;
      height: 44px;
      line-height: 44px;
      color: #999999;
      text-align: center;
      font-size: 14px;
      white-space: nowrap;
      cursor: pointer;
      &:hover {
        color: #fb8c24;
      }
      &:not(:last-child) {
        border-right: 1px solid #e8e8e8;
      }
    }
  }
}
.el-dialog {
  background: #f5f5f5 !important;
}
</style>
